package com.xplay.xpocker.room.mahjong.dto;

import com.xplay.xpocker.constant.ConstantDict;
import com.xplay.xpocker.room.RoomType;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public enum CdRuleEnum {
    HSZ(RuleConstant.HSZ, "换三张"), HJZY("HJZY", "呼叫转移"), CG("CG", "擦挂"), GSJFKHo("GSJFKH", "过手加番可胡"), LZ("LZ", "轮庄"), GZGH("GZGH", "过庄过胡"), TDH("TDH", "天地胡"), SJBSJ("SJBSJ", "死叫不算叫"), GPGQ("GPGQ", "过碰过圈"), YHBH("YHBH", "有胡必胡"), LFQH("LFQH", "两分起胡"), DDHFLF("DDHFLF", "对对胡翻两番"), JXW("JXW", "夹心五"), JZJF("JZJF", "绝张加番"), LZWF("LZWF", "癞子玩法"), WLZJF("WLZJF", "无癞子加番"), YTL("YTL", "一条龙"), JSY("JSY", "及时雨"), MQZZ("MQZZ", "门清中张"), YJJD("YJJD", "幺九将对"), XSLS("XSLS", "显示流水"), CHZXZ("CHZXZ", "查花猪限制"),
    ;

    static {
        RULE_CACHE = Arrays.stream(CdRuleEnum.values()).collect(Collectors.toMap(CdRuleEnum::getCode, Function.identity()));
    }

    public static final Map<String, CdRuleEnum> RULE_CACHE;
    public String code;
    public String name;

    public static CdRuleEnum of(String type) {
        return RULE_CACHE.get(type);
    }

    /**
     * 校验规则是否包含某个规则
     *
     * @param rules
     * @param ruleEnum
     * @return
     */

    public static boolean contain(List<String> rules, CdRuleEnum ruleEnum) {
        if (rules == null || rules.size() == 0) {
            return false;
        }
        return rules.stream().anyMatch(item -> RULE_CACHE.get(item) != null);
    }

    CdRuleEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
